/*     */ package com.wgcloud.service;
/*     */ 
/*     */ import com.github.pagehelper.PageHelper;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.ShellInfo;
/*     */ import com.wgcloud.entity.ShellState;
/*     */ import com.wgcloud.mapper.ShellInfoMapper;
/*     */ import com.wgcloud.mapper.ShellStateMapper;
/*     */ import com.wgcloud.service.ShellStateService;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import com.wgcloud.util.UUIDUtil;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Service;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ 
/*     */ 
/*     */ 
/*     */ @Service
/*     */ public class ShellInfoService
/*     */ {
/*     */   @Autowired
/*     */   private ShellInfoMapper shellInfoMapper;
/*     */   @Autowired
/*     */   private ShellStateMapper shellStateMapper;
/*     */   @Autowired
/*     */   private ShellStateService shellStateService;
/*     */   
/*     */   public PageInfo selectByParams(Map<String, Object> params, int currPage, int pageSize) throws Exception {
/*  34 */     PageHelper.startPage(currPage, pageSize);
/*  35 */     List<ShellInfo> list = this.shellInfoMapper.selectByParams(params);
/*  36 */     PageInfo<ShellInfo> pageInfo = new PageInfo(list);
/*  37 */     return pageInfo;
/*     */   }
/*     */   
/*     */   public void save(ShellInfo shellInfo, String[] hostnames) throws Exception {
/*  41 */     shellInfo.setId(UUIDUtil.getUUID());
/*  42 */     shellInfo.setState("1");
/*  43 */     shellInfo.setCreateTime(DateUtil.getNowTime());
/*  44 */     if (!StringUtils.isEmpty(shellInfo.getShell())) {
/*  45 */       shellInfo.setShell(shellInfo.getShell().trim());
/*     */     }
/*  47 */     List<ShellState> shellStateList = new ArrayList<>();
/*  48 */     for (String hostname : hostnames) {
/*  49 */       ShellState shellState = new ShellState();
/*  50 */       shellState.setShellId(shellInfo.getId());
/*  51 */       shellState.setHostname(hostname);
/*  52 */       shellState.setCreateTime(shellInfo.getCreateTime());
/*  53 */       shellState.setShell(shellInfo.getShell());
/*  54 */       shellState.setState("1");
/*  55 */       shellStateList.add(shellState);
/*     */     } 
/*  57 */     this.shellInfoMapper.save(shellInfo);
/*  58 */     this.shellStateService.saveRecord(shellStateList);
/*     */   }
/*     */ 
/*     */   
/*     */   @Transactional
/*     */   public void saveRecord(List<ShellInfo> recordList) throws Exception {
/*  64 */     if (recordList.size() < 1) {
/*     */       return;
/*     */     }
/*  67 */     for (ShellInfo as : recordList) {
/*  68 */       as.setId(UUIDUtil.getUUID());
/*     */     }
/*  70 */     this.shellInfoMapper.insertList(recordList);
/*     */   }
/*     */   
/*     */   public int countByParams(Map<String, Object> params) throws Exception {
/*  74 */     return this.shellInfoMapper.countByParams(params);
/*     */   }
/*     */   
/*     */   @Transactional
/*     */   public int deleteById(String[] id) throws Exception {
/*  79 */     for (String shellInfoId : id) {
/*  80 */       this.shellStateMapper.cancelByShellId(shellInfoId);
/*     */     }
/*  82 */     return this.shellInfoMapper.deleteById(id);
/*     */   }
/*     */   
/*     */   @Transactional
/*     */   public void updateRecord(List<ShellInfo> recordList) throws Exception {
/*  87 */     if (recordList.size() < 1) {
/*     */       return;
/*     */     }
/*  90 */     this.shellInfoMapper.updateList(recordList);
/*     */   }
/*     */   
/*     */   public void updateById(ShellInfo shellInfo) throws Exception {
/*  94 */     this.shellInfoMapper.updateById(shellInfo);
/*     */   }
/*     */   
/*     */   @Transactional
/*     */   public void cancelShell(String id) throws Exception {
/*  99 */     ShellInfo shellInfo = this.shellInfoMapper.selectById(id);
/* 100 */     shellInfo.setState("2");
/* 101 */     this.shellInfoMapper.updateById(shellInfo);
/* 102 */     this.shellStateMapper.cancelByShellId(id);
/*     */   }
/*     */   
/*     */   @Transactional
/*     */   public void restart(String id) throws Exception {
/* 107 */     ShellInfo shellInfo = this.shellInfoMapper.selectById(id);
/* 108 */     shellInfo.setState("1");
/* 109 */     shellInfo.setCreateTime(new Date());
/* 110 */     this.shellInfoMapper.updateById(shellInfo);
/* 111 */     this.shellStateMapper.restartByShellId(id);
/*     */   }
/*     */   
/*     */   public ShellInfo selectById(String id) throws Exception {
/* 115 */     return this.shellInfoMapper.selectById(id);
/*     */   }
/*     */   
/*     */   public List<ShellInfo> selectAllByParams(Map<String, Object> params) throws Exception {
/* 119 */     return this.shellInfoMapper.selectAllByParams(params);
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/service/ShellInfoService.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */